#include <typeinfo>
#include "stdafx.h"
#include "ChessPiece.h"
#include "FileUtility.h"
#include "BasicRule.h"


ChessPiece::ChessPiece(void)
{
	isActive = true;
	isSelected = false;

}

ChessPiece::~ChessPiece(void)
{
	//BoardCell::~BoardCell();
	selectedImagePointer.Free();
	free(selectedImagePointer);
}

GdiplusImagePtr* ImagePointer = (GdiplusImagePtr*) malloc(sizeof(GdiplusImagePtr)+1);

void ChessPiece::SetImage(std::string fileDir)
{
	//wchar_t* wFileDir = ConvertToWcharT(fileDir);
	wchar_t* wFileDir = FileUtility::GetInstance()->ConvertToWcharT(fileDir);
	ImagePointer.Attach(new Gdiplus::Image(wFileDir));
}

void ChessPiece::SetXPosition(int x)
{
	drawPosition.x = x;
}

int ChessPiece::GetXPosition()
{
	return drawPosition.x;
}

void ChessPiece::SetYPosition(int y)
{
	drawPosition.y = y;
}

int ChessPiece::GetYPosition()
{
	return drawPosition.y;
}



void ChessPiece::SetRow(int inputRow)
{
	if(inputRow>=0)
	{
		boardPosition.y = inputRow;
	}
}
	
int ChessPiece::GetRow()
{
	return boardPosition.y;
}
	
void ChessPiece::SetCollumn(int inputCollumn)
{
	if(inputCollumn>=0)
	{
		boardPosition.x = inputCollumn;
	}
}
	
int ChessPiece::GetCollumn()
{
	return boardPosition.x;
}

void ChessPiece::SetDeactive()
{
	isActive = FALSE;
}

void ChessPiece::SetActive()
{
	isActive = TRUE;
}

bool ChessPiece::IsActive()
{
	return this->isActive;
}

//void ChessPiece::setBoard(Board* board)
//{
//	this->m_Board = board;
//}

void ChessPiece::Update()
{
	int cellDistance = ConstValue::padding + ConstValue::cellHeightWidth;
	drawPosition.x = (boardPosition.x) * cellDistance + ConstValue::xBeginDraw ;
	drawPosition.y = (boardPosition.y) * cellDistance + ConstValue::yBeginDraw ;
}

void ChessPiece::ChangeSelectedState()
{
	if(isSelected == true)
	{
		isSelected = false;
	}
	else
	{
		isSelected = true;
	}
}

bool ChessPiece::IsSelected()
{
	return isSelected;
}

void ChessPiece::SetSelectedImage(std::string fileDir)
{
	//wchar_t* wFileDir = ConvertToWcharT(fileDir);
	wchar_t* wFileDir = FileUtility::GetInstance()->ConvertToWcharT(fileDir);
	selectedImagePointer.Attach(new Gdiplus::Image(wFileDir));
}

void ChessPiece::Draw(Gdiplus::Graphics &graphics)
{
	if(isSelected == false)
	{
		graphics.DrawImage(ImagePointer, drawPosition.x, drawPosition.y);
	}
	else
	{
		graphics.DrawImage(selectedImagePointer, drawPosition.x, drawPosition.y);
	}
}

void ChessPiece::SetRedSide(bool side)
{
	isRedSide = side;
}

bool ChessPiece::IsRedSide()
{
	return isRedSide;
}

bool ChessPiece::CanMoveTo(POINT currPos, POINT newPos)
{
	return true;
}

void ChessPiece::WriteLogPieceTurn(HWND hListBox,bool isRedSide, POINT currPos, POINT newPos)
{

}

void ChessPiece::MoveAuto(POINT currPos, POINT newPos)
{

}
//int ChessPiece::CountNumberPieceSameTypeInColumn(char* nameclass, int col)
//{
//	return 0;
//}